﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GBIT.Web;
using WebComponents;
using WebComponents.Security;
using WebComponents.Data;

public partial class ThemNhaSanXuat : UserControlBase {
  int manuId = -1;
  protected void Page_Load(object sender, EventArgs e) {
    //ImagePath.RequiredFieldValidator = true;
    manuId = ConvertType.ToInt(Request.Params["id"]);
    this.Title = "Nhà sản xuất";
    this.TaskTitle = "Thêm mới";   
    if (manuId > 0) {
      if (!IsPostBack) {
        LoadManu(manuId);
        this.TaskTitle = "Cập nhật";
      }
    } 
    this.SaveEnabled = true;
  }

  protected void LoadManu(int ManuId) {
    ManufacturerInfo obj = ManufacturerController.GetByManuID(ManuId);
    txtTitle.Text = obj.ManufacturerVi;   
    ImagePath.ImagePath = obj.ImageUrl;
    ImagePath.ImageUrl = obj.ImageUrl;
  }
  protected override void OnSaveRecord(bool redirect) {
    ManufacturerInfo obj = null;
    if (manuId > 0)
      obj = ManufacturerController.GetByManuID(manuId);
    if (obj == null)
      obj = new ManufacturerInfo();
    obj.ManufacturerVi = txtTitle.Text.Trim();    
    obj.ImageUrl = ImagePath.ImagePath;   
    if (manuId > 0) {
      ManufacturerController.Update(obj);
    } else {
      ManufacturerController.Insert(obj);
    }
    Security.ShowClientMessage(Page, "Lưu trữ thông tin nhà sản xuất thành công!", string.Format("?mod={0}", WebComponents.ConvertType.Encode("NhaSanXuat/NhaSanXuatList.ascx")));
  }
}
